//
//  ViewController.swift
//  RxSwiftExpriOne
//
//  Created by DeLong Yang on 2017/7/28.
//  Copyright © 2017年 YiXue. All rights reserved.
/*
    1.0 in UIStoryBoard you have to
 */

import UIKit
import RxSwift
import RxCocoa   // 引入 rxcocoa

struct Speaker {
    let name: String
    let twitterHandler: String
    var image: UIImage?
    
    init(name:String,twitterHandler:String) {
        self.name = name
        self.twitterHandler = twitterHandler
        // remove the space with ,,..<>;;::---==+++++=000{}
        image = UIImage(named: name.replacingOccurrences(of: " ", with: ""))
        
    }
}

extension Speaker: CustomStringConvertible{
    var description: String{
        return "\(name) \(twitterHandler)"
    }
}


struct SpeakerListViewModel{
    let  data = Observable.just([
            Speaker(name: "Ben Sandofsky", twitterHandler: "@sandofsky"),
            Speaker(name: "Carla White", twitterHandler: "@carlawhite"),
            Speaker(name: "Jaimee Newberry", twitterHandler: "@jaimeejaimee"),
            Speaker(name: "Natasha Murashev", twitterHandler: "@natashatherobot"),
            Speaker(name: "Robi Ganguly", twitterHandler: "@rganguly"),
            Speaker(name: "Virginia Roberts",  twitterHandler: "@askvirginia"),
            Speaker(name: "Scott Gardner", twitterHandler: "@scotteg")
         ])
}

class ViewController: UIViewController,UITableViewDelegate {

    @IBOutlet weak var speakerListTableView: UITableView!
    
    let speakerListViewModel = SpeakerListViewModel()
    let disposeBag = DisposeBag()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
//        speakerListViewModel.data.bind(to: speakerListTableView.rx_item)
        let items = Observable.just((0..<20).map{"\($0)"})
        
        
        items.bind(to: speakerListTableView.rx.items(cellIdentifier: "Cell", cellType: UITableViewCell.self)) { (row, element, cell) in
                cell.textLabel?.text = "\(element) @ row \(row)"
            }
            .disposed(by: disposeBag)
        
            //
        speakerListTableView.rx
            .modelSelected(String.self)
            .subscribe(onNext:  { value in
                print("Tapped `\(value)`")
            })
            .disposed(by: disposeBag)
        //
//        speakerListTableView.rx.itemAccessoryButtonTapped.subscribe(onNext: { (indexPath) in
//            print(indexPath.ro
//        }, onError: nil, onCompleted: nil) { 
//           
//        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
























































































































